package com.lxyk.controller.monthly;

import com.lxyk.dao.monthly.CourseInfoDao;
import com.lxyk.domain.CourseInfo;
import com.lxyk.service.monthly.CourseInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/courseInfo")
public class CourseInfoController {

    @Autowired
    private CourseInfoService courseInfoService;

    //根据班级id查询班级课程信息
    @RequestMapping("/findAllByCid")
    public String findAllByCid(Integer cid, Model model){
        List<CourseInfo> list = courseInfoService.findAllByCid(cid);
        model.addAttribute("list",list);
        model.addAttribute("cid",cid);
        return "courseinfo-list";
    }

    //ajax修改上课时间
    @RequestMapping("/editDate")
    public void editDate(Integer id, String date){
        courseInfoService.editDateById(id, date);
    }

    //删除
    @RequestMapping("/deleteById")
    public String deleteById(Integer id,Integer cid){
        courseInfoService.deleteById(id,cid);
        return "redirect:findAllByCid?cid="+cid;
    }

    //跳到添加课程页面
    @RequestMapping("/toAddCourseInfoPage")
    public String toAddCourseInfoPage(Integer cid,Model model){
        model.addAttribute("cid",cid);
        return "courseInfo-add";
    }

    //添加课程
    @RequestMapping("/addCourseInfo")
    public String addCourseInfo(CourseInfo courseInfo,Model model){
        courseInfoService.addCourseInfo(courseInfo);
        return "redirect:findAllByCid?cid="+courseInfo.getCid();
    }

}
